home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0173_Component to give access to Application.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-30  |  3.3 KB  |  125 lines

  1. unit App_prop;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs;
  8.  
  9. type
  10.   TDuplicateError = class(Exception);
  11.   TMainFormError = class(Exception);
  12.   TApplicationProperties = class(TComponent)
  13.   private
  14.     { Private declarations }
  15.     fHint : String;
  16.     fHintColor : TColor;
  17.     fHintPause : Integer;
  18.     fShowHint : Boolean;
  19.  
  20.     fOnActivate : TNotifyEvent;
  21.     fOnDeactivate : TNotifyEvent;
  22.     fOnException : TExceptionEvent;
  23.     fOnHelp : THelpEvent;
  24.     fOnHint : TNotifyEvent;
  25.     fOnIdle : TIdleEvent;
  26.     fOnMessage : TMessageEvent;
  27.   protected
  28.     { Protected declarations }
  29.   public
  30.     { Public declarations }
  31.     constructor Create(AOwner: TComponent);
  32.       override;
  33.     destructor Destroy;
  34.       override;
  35.     procedure Loaded;
  36.       override;
  37.   published
  38.     { Published declarations }
  39.     property Hint : String
  40.       read fHint write fHint;
  41.     property HintColor : TColor
  42.       read fHintColor write fHintColor;
  43.     property HintPause : Integer
  44.       read fHintPause write fHintPause;
  45.     property ShowHint : Boolean
  46.       read fShowHint write fShowHint;
  47.  
  48.     property OnActivate : TNotifyEvent
  49.       read fOnActivate write fOnActivate;
  50.     property OnDeactivate : TNotifyEvent
  51.       read fOnDeactivate write fOnDeactivate;
  52.     property OnException : TExceptionEvent
  53.       read fOnException write fOnException;
  54.     property OnHelp : THelpEvent
  55.       read fOnHelp write fOnHelp;
  56.     property OnHint : TNotifyEvent
  57.       read fOnHint write fOnHint;
  58.     property OnIdle : TIdleEvent
  59.       read fOnIdle write fOnIdle;
  60.     property OnMessage : TMessageEvent
  61.       read fOnMessage write fOnMessage;
  62.   end;
  63.  
  64. procedure Register;
  65.  
  66. implementation
  67.  
  68. var
  69.   ComponentCounter : Integer;
  70.  
  71. constructor TApplicationProperties.Create(AOwner: TComponent);
  72. begin
  73.   inherited Create(AOwner);
  74.   Inc(ComponentCounter);
  75.   if ComponentCounter > 1 then
  76.     raise TDuplicateError.Create('You can have only ' +
  77.       'one ApplicationProperties component in a project');
  78.  
  79.   fHintColor := Application.HintColor;
  80.   fHintPause := Application.HintPause;
  81.   fShowHint := Application.ShowHint;
  82. end;
  83.  
  84. destructor TApplicationProperties.Destroy;
  85. begin
  86.   inherited Destroy;
  87.   Dec(ComponentCounter);
  88. end;
  89.  
  90. procedure TApplicationProperties.Loaded;
  91. begin
  92.   if fHint <> '' then
  93.     Application.Hint := fHint;
  94.   if fHintColor <> Application.HintColor then
  95.     Application.HintColor := fHintColor;
  96.   if fHintPause <> Application.HintPause then
  97.     Application.HintPause := fHintPause;
  98.   if fShowHint <> Application.ShowHint then
  99.     Application.ShowHint := fShowHint;
  100.  
  101.   if Assigned(fOnActivate) then
  102.     Application.OnActivate := fOnActivate;
  103.   if Assigned(fOnDeactivate) then
  104.     Application.OnDeactivate := fOnDeactivate;
  105.   if Assigned(fOnException) then
  106.     Application.OnException := fOnException;
  107.   if Assigned(fOnHelp) then
  108.     Application.OnHelp := fOnHelp;
  109.   if Assigned(fOnHint) then
  110.     Application.OnHint := fOnHint;
  111.   if Assigned(fOnIdle) then
  112.     Application.OnIdle := fOnIdle;
  113.   if Assigned(fOnMessage) then
  114.     Application.OnMessage := fOnMessage;
  115. end;
  116.  
  117. procedure Register;
  118. begin
  119.   RegisterComponents('Samples', [TApplicationProperties]);
  120. end;
  121.  
  122. initialization
  123.   ComponentCounter := 0;
  124. end.
  125.